package makovo.ajax;

import java.io.IOException;
import java.io.PrintWriter;
import java.sql.SQLException;
import java.util.List;
import java.util.Map;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import makovo.data.Resources;

import makovo.entities.Applicant.ApplicantStep;

import org.apache.struts2.interceptor.SessionAware;
import org.json.JSONException;
import org.json.JSONObject;

public class Documents extends HttpServlet implements SessionAware {
	private static final long serialVersionUID = 1L;
	private String mCurp = null;

	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		HttpSession session = request.getSession();
		mCurp = (String) session.getAttribute("User.idSender");

		try {
			boolean success = Resources.changeApplicantStep(mCurp, ApplicantStep.UPLOAD_HOME);

			if (success) {

				response.setCharacterEncoding("utf8");
				response.setContentType("application/json");
				PrintWriter out = response.getWriter();

				JSONObject obj = new JSONObject();

				obj.put("redirect", "../tareas/documentos_vivienda.jsp");

				out.print(obj);

			} else
				throw new IllegalArgumentException();
		} catch (Exception e) {
			e.printStackTrace();
		}
	}

	@Override
	public void setSession(Map<String, Object> session) {
	}

}
